package com.ruoyi.web.controller.apply;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.ApplyInfo;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.IApplyInfoService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 制作申请Controller
 * 
 * @author ess
 * @date 2021-10-25
 */
@Api("申请记录-2")
@RestController
@RequestMapping("/apply/make")
public class ApplyMakeController extends BaseController
{
    @Autowired
    private IApplyInfoService applyInfoService;

    /**
     * 查询制作申请列表
     * 查询当前角色管辖范围内的未审核的申请记录
     */
    @PreAuthorize("@ss.hasPermi('apply:make:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApplyInfo applyInfo)
    {
        startPage();
        applyInfo.setApplyState(1L);
        List<ApplyInfo> list = applyInfoService.selectApplyInfoList(applyInfo);
        return getDataTable(list);
    }

    /**
     * 导出制作申请列表
     */
    @PreAuthorize("@ss.hasPermi('apply:make:export')")
    @Log(title = "制作申请", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ApplyInfo applyInfo)
    {
        List<ApplyInfo> list = applyInfoService.selectApplyInfoList(applyInfo);
        ExcelUtil<ApplyInfo> util = new ExcelUtil<ApplyInfo>(ApplyInfo.class);
        return util.exportExcel(list, "制作申请数据");
    }

    /**
     * 获取制作申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('apply:make:query')")
    @GetMapping(value = "/{applyInfoId}")
    public AjaxResult getInfo(@PathVariable("applyInfoId") String applyInfoId)
    {
        return AjaxResult.success(applyInfoService.selectApplyInfoByApplyInfoId(applyInfoId));
    }

    /**
     * 新增制作申请
     */
    @PreAuthorize("@ss.hasPermi('apply:make:add')")
    @Log(title = "制作申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApplyInfo applyInfo)
    {
        return toAjax(applyInfoService.insertApplyInfo(applyInfo));
    }

    /**
     * 修改制作申请
     */
    @PreAuthorize("@ss.hasPermi('apply:make:edit')")
    @Log(title = "制作申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApplyInfo applyInfo)
    {
        return toAjax(applyInfoService.updateApplyInfo(applyInfo));
    }

    /**
     * 删除制作申请
     */
    @PreAuthorize("@ss.hasPermi('apply:make:remove')")
    @Log(title = "制作申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{applyInfoIds}")
    public AjaxResult remove(@PathVariable String[] applyInfoIds)
    {
        return toAjax(applyInfoService.deleteApplyInfoByApplyInfoIds(applyInfoIds));
    }
}
